    var DETAIL_IMAGE_SELECTOR = '[data-image-role="target"]';
    var DETAIL_TITLE_SELECTOR = '[data-image-role="title"]';
    var THUMBNAIL_LINK_SELECTOR = '[data-image-role="trigger"]';
    var HIDDEN_DETAIL_CLASS= 'hidden-detail';
    var TINY_EFFECT_CLASS = 'is-tiny';
    var DETAIL_FRAME_SELECTOR = '[data-image-role="frame"]';
    var ESC_KEY = 27;
    function setDetail(imageUrl,titleText) {

        var detailImage = document.querySelector(DETAIL_IMAGE_SELECTOR);
        detailImage.setAttribute('src',imageUrl);
        var detailTitle = document.querySelector(DETAIL_TITLE_SELECTOR);
        detailTitle.textContent = titleText;
    }

    //获取传入的略缩图的image
    function imageFromThumb(thumbnail) {
        return thumbnail.getAttribute('data-image-url');
    }
    //获取传入的略缩图的title
    function titleFromThumb(thumbnail) {
        return thumbnail.getAttribute('data-image-title');
    }
    function setDetailFromThumb(thumbnail) {
        setDetail(imageFromThumb(thumbnail),titleFromThumb(thumbnail));
    }
    function addThumbClickHandler(thumb) {
        thumb.addEventListener('click',function (event) {
            event.preventDefault();
            setDetailFromThumb(thumb);
            showDetail();
        });
    }
    function getThumbsArray() {
        var thumb = document.querySelectorAll(THUMBNAIL_LINK_SELECTOR);

        return [].slice.call(thumb);
    }
    //隐藏大图
    function hideDetails() {
        document.body.classList.add(HIDDEN_DETAIL_CLASS);
    }
    //显示大图
    function showDetail() {
        var frame = document.querySelector(DETAIL_FRAME_SELECTOR);

        frame.classList.add(TINY_EFFECT_CLASS);
        setTimeout(function () {
            document.body.classList.remove(HIDDEN_DETAIL_CLASS);
        },50);
        frame.classList.remove(TINY_EFFECT_CLASS);
    }
    //触发按键隐藏大图
    function addKeyPressHandler() {
        document.body.addEventListener('keyup',function (ev) {
            ev.preventDefault();
            if(ev.keyCode == ESC_KEY){
                hideDetails();
            }
        });
    }
    function initiaLizeEvents() {
        var thumbs = getThumbsArray();
        thumbs.forEach(addThumbClickHandler);
        addKeyPressHandler();
    }

    initiaLizeEvents();
